package org.geektimes.projects.user.repository;

import org.geektimes.projects.user.domain.User;
import org.geektimes.projects.user.sql.DBConnectionManager;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;

/**
 * @author :   chuan
 * @date :   2021/03/01
 */
public class HomeworkUserRepository implements UserRepository {

    private final DBConnectionManager dbConnectionManager;
    public HomeworkUserRepository() {
        this.dbConnectionManager = new DBConnectionManager();
    }

    @Override
    public boolean save(User user) throws SQLException {

        Connection connection = dbConnectionManager.getConnection();
        Statement statement = connection.createStatement();

        String sql = String.format("INSERT INTO users(name, password, email, phoneNumber) VALUES ('%s', '%s', '%s', '%s')",
                user.getName(), user.getPassword(), user.getEmail(), user.getPhoneNumber());

        int i = statement.executeUpdate(sql);

        return false;
    }

    @Override
    public boolean deleteById(Long userId) {
        return false;
    }

    @Override
    public boolean update(User user) {
        return false;
    }

    @Override
    public User getById(Long userId) {
        return null;
    }

    @Override
    public User getByNameAndPassword(String userName, String password) {
        return null;
    }

    @Override
    public Collection<User> getAll() {
        return null;
    }
}
